<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="../css/login.css" />
    <link rel="stylesheet" href="../css/base.css" />
    <script src="../js/login.js"></script>
    <script src="../js/jquery.js"></script>
  </head>
  <body>
    <!-- 登录页 -->
    <div class="header">
      <img src="../img/logo.png" alt="" />
    </div>
    <div class="ban">
      <div class="box">
        <img src="../img/0.png" alt="" />

        <div class="ccc">
          <h1>使用合作号登录</h1>
          <h2>账号密码登录</h2>
          <input type="text" / placeholder="手机号" class="phone">
          <span style="display: none"></span><input type="text" /
          placeholder="密码" class="password"><span
            style="display: none"
          ></span>
          <span>登录</span>
          <ul>
            <li>短信验证登录</li>
            <li><a href="../html/reg.html">注册</a></li>
            <li>找回密码</li>
          </ul>
          <h3>我已阅读并同意 《隐私协议》与《用户服务协议》</h3>
        </div>
      </div>
    </div>
    <script>
      var oInput = document.querySelectorAll("input");
      var ospan = document.querySelectorAll("span");
      // 账号
      var reg = /\S/;
      oInput[0].onblur = function () {
        var val = this.value;
        if (reg.test(val) == false) {
          ospan[0].innerText = "参数不能为空";
          ospan[0].style.display = "block";
        } else {
          ospan[0].style.display = "none";
          // ospan[0].innerText="输入正确";
          // after("输入正确");
        }
      };
      // 密码
      var reg = /\S/;
      oInput[1].onblur = function () {
        var val = this.value;
        if (reg.test(val) == false) {
          ospan[1].innerText = "参数不能为空";
        } else {
          ospan[0].style.display = "none";
          // after("输入正确");
        }
      };

      $("span").click(function () {
        $.get("http://jx.xuzhixiang.top/ap/api/login.php", {
          username: $(".phone").val(),
          password: $(".password").val(),
        }).then((res) => {
          if (res.code == 1) {
            // let uid = res.data.id;
            location.href = `../html/index.html?uid=${res.data.id}`;
          } else {
            alert("账号或密码错误");
          }
          let name = res.data.username;
          let password = res.data.password;
          let id = res.data.id;
          let data = { name: name, pass: password, uid: id };
          localStorage.setItem("id", JSON.stringify(data));
        });
      });
    </script>
  </body>
</html>
